import { getsysLogList } from '@/services';
import { ISysLog } from '@/types';
import { Effect, Reducer } from 'umi';

export interface sysLogModelState {
  sysLogList: ISysLog[];
  sysLogListLength: number;
}
export interface sysLogTagModelType {
  namespace: 'sysLog';
  state: sysLogModelState;
  effects: {
    getsysLogList: Effect;
  };
  reducers: {
    save: Reducer<sysLogModelState>;
  };
}
const MenuModel: sysLogTagModelType = {
  namespace: 'sysLog',
  state: {
    sysLogList: [],
    sysLogListLength: 0,
  },
  effects: {
    *getsysLogList({ payload }, { call, put, select }) {
      let result = yield call(getsysLogList, payload);
      if (result) {
        yield put({
          type: 'save',
          payload: {
            sysLogList: result.records.map((item: any,index:number) => {
              item.key = item.id;
              item.index = index+1
              return item;
            }),
            sysLogListLength: result.total,
          },
        });
      }
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};

export default MenuModel;
